package com.platform.core.web.controller;

import com.platform.comm.web.results.DataJsonResult;
import com.platform.comm.web.results.JsonResult;
import com.platform.comm.web.results.PageListJsonResult;
import com.platform.core.service.CdJxcManageBiz;
import com.platform.dto.CdJxcManageDto;
import com.platform.dto.CdJxcManageProd;
import org.apache.commons.collections4.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * Description: -管理接口
 *
 * @author Coder
 */
@RestController
@RequestMapping(name = "管理", path = "/management/cdJxcManage")
public class CdJxcManageController extends BaseController{

    private final CdJxcManageBiz cdJxcManageBiz;

    @Autowired
    public CdJxcManageController(CdJxcManageBiz cdJxcManageBiz) {
        this.cdJxcManageBiz = cdJxcManageBiz;
    }

    /**
     * 分页查询数据
     */
    @PostMapping(name = "查询列表", path = "/search")
    public PageListJsonResult<CdJxcManageDto> search(@RequestBody Map<String,String> params) {
        Page<CdJxcManageDto> entities = cdJxcManageBiz.search(params, getPageable(params));
        return new PageListJsonResult<>(entities);
    }

    /**
     * 实时分析
     */
    @PostMapping(name = "查询列表", path = "/jxcSearch")
    public DataJsonResult<List<CdJxcManageDto>> jxcSearch(@RequestBody CdJxcManageDto dto) {
        List<CdJxcManageDto> cdJxcManageDtos = cdJxcManageBiz.jxcSearch(dto);
        return DataJsonResult.succeed(cdJxcManageDtos);
    }

    /**
    * 查询明细数据
    */
    @PostMapping(name = "查询明细", path = "/detail")
    public DataJsonResult<CdJxcManageDto> detail(@RequestParam String id) {
        return DataJsonResult.succeed(cdJxcManageBiz.detail(id));
    }

    /**
    * 新增
    */
    @PostMapping(name = "新增", path = "/create")
    public JsonResult create(@RequestBody CdJxcManageDto req) {
        cdJxcManageBiz.add(req);
        return JsonResult.success();
    }

    /**
     * 批量新增
     */
    @PostMapping(name = "批量新增", path = "/batchCreate")
    public JsonResult batchCreate(@RequestBody CdJxcManageProd req) {
        cdJxcManageBiz.batchCreate(req);
        return JsonResult.success();
    }

    /**
    * 修改数据
    */
    @PostMapping(name = "修改", path = "/modify")
    public JsonResult modifyCdJxcManage(@RequestBody CdJxcManageDto req) {
        cdJxcManageBiz.modify(req);
        return JsonResult.success();
    }

    /**
    * 删除
    */
    @PostMapping(name = "删除", path = "/remove")
    public JsonResult remove(@RequestBody Map<String,String> params) {
        String id = MapUtils.getString(params, "id");
        cdJxcManageBiz.remove(id);
        return JsonResult.success();
    }
}
